﻿#include "StartUp.h"

#include "Framework/Application.h"
#include "Framework/Editor.h"


#include "Ability/Group/EditorAbilityGroupModel.h"
#include "Ability/Group/EditorAbilityGroupViewModel.h"
#include "Ability/Group/EditorAbilityGroupView.h"

#include "Ability/Explorer/EditorExplorerAbilityGroupModel.h"
#include "Ability/Explorer/EditorExplorerAbilityGroupViewModel.h"
#include "Ability/Explorer/EditorExplorerAbilityGroupView.h"

#include "Ability/DebugAndRun/EditorDebugAndRunAbilityGroupModel.h"
#include "Ability/DebugAndRun/EditorDebugAndRunAbilityGroupViewModel.h"
#include "Ability/DebugAndRun/EditorDebugAndRunAbilityGroupView.h"

#include "Ability/Breakpoint/EditorBreakpointAbilityModel.h"
#include "Ability/Breakpoint/EditorBreakpointAbilityViewModel.h"
#include "Ability/Breakpoint/EditorBreakpointAbilityView.h"

#include "Ability/Variable/EditorVariableAbilityModel.h"
#include "Ability/Variable/EditorVariableAbilityViewModel.h"
#include "Ability/Variable/EditorVariableAbilityView.h"

#include "Ability/CallStack/EditorCallStackAbilityModel.h"
#include "Ability/CallStack/EditorCallStackAbilityViewModel.h"
#include "Ability/CallStack/EditorCallStackAbilityView.h"

#include "Ability/Output/EditorOutputAbilityModel.h"
#include "Ability/Output/EditorOutputAbilityViewModel.h"
#include "Ability/Output/EditorOutputAbilityView.h"

#include "Ability/DebugConsole/EditorDebugConsoleModel.h"
#include "Ability/DebugConsole/EditorDebugConsoleViewModel.h"
#include "Ability/DebugConsole/EditorDebugConsoleView.h"

#include "Ability/Folder/EditorFolderAbilityModel.h"
#include "Ability/Folder/EditorFolderAbilityViewModel.h"
#include "Ability/Folder/EditorFolderAbilityView.h"

#include "Ability/SceneOutline/EditorSceneOutlineAbilityModel.h"
#include "Ability/SceneOutline/EditorSceneOutlineAbilityViewModel.h"
#include "Ability/SceneOutline/EditorSceneOutlineAbilityView.h"

#include "Ability/MaterialPreview/EditorMaterialPreviewAbilityModel.h"
#include "Ability/MaterialPreview/EditorMaterialPreviewAbilityViewModel.h"
#include "Ability/MaterialPreview/EditorMaterialPreviewAbilityView.h"

#include "Ability/EngineObject/EditorEngineObjectAbilityGroupModel.h"
#include "Ability/EngineObject/EditorEngineObjectAbilityGroupViewModel.h"
#include "Ability/EngineObject/EditorEngineObjectAbilityGroupView.h"

#include "Ability/ObjectProperty/EditorObjectPropertyAbilityModel.h"
#include "Ability/ObjectProperty/EditorObjectPropertyAbilityViewModel.h"
#include "Ability/ObjectProperty/EditorObjectPropertyAbilityView.h"

#include "Property/NodePosition/EditorNodePositionPropertyModel.h"
#include "Property/NodePosition/EditorNodePositionPropertyViewModel.h"
#include "Property/NodePosition/EditorNodePositionPropertyView.h"

#include "Property/NodeRotation/EditorNodeRotationPropertyModel.h"
#include "Property/NodeRotation/EditorNodeRotationPropertyViewModel.h"
#include "Property/NodeRotation/EditorNodeRotationPropertyView.h"

#include "Property/NodeScale/EditorNodeScalePropertyModel.h"
#include "Property/NodeScale/EditorNodeScalePropertyViewModel.h"
#include "Property/NodeScale/EditorNodeScalePropertyView.h"

#include "Property/Component/EditorComponentPropertyModel.h"
#include "Property/Component/EditorComponentPropertyViewModel.h"
#include "Property/Component/EditorComponentPropertyView.h"

#include "Property/AddComponent/EditorAddComponentPropertyModel.h"
#include "Property/AddComponent/EditorAddComponentPropertyViewModel.h"
#include "Property/AddComponent/EditorAddComponentPropertyView.h"

#include "Property/ReflectedProperty/EditorReflectedPropertyModel.h"
#include "Property/ReflectedProperty/EditorReflectedPropertyViewModel.h"
#include "Property/ReflectedProperty/EditorReflectedPropertyView.h"

#include "Property/MeshMaterial/EditorMeshMaterialPropertyModel.h"
#include "Property/MeshMaterial/EditorMeshMaterialPropertyViewModel.h"
#include "Property/MeshMaterial/EditorMeshMaterialPropertyView.h"

#include "MaterialGraph/MaterialGprah.h"
#include "StatusBar/StatusBar.h"
#include "Notification/Notification.h"
#include "Pages/Page.h"
#include "Window/EditorWindow.h"

#include "Window/EditorWindowGroupModel.h"

#include "Asset/EngineDefaultPackage.h"
#include "Scene/Scene.h"
#include "Scene/StaticMeshComponent.h"
#include "Scene/DirectionalLightComponent.h"
#include "Scene/CameraComponent.h"
#include "Scene/InputComponent.h"


#include "Material/MaterialSubsystem.h"


void WHE::RunEditor()
{
    //register all the classes
    auto Editor=REditor::Get();
    Editor->RegisterMVVM(
        REditorExplorerAbilityGroupModel::StaticClass()
        , REditorExplorerAbilityGroupViewModel::StaticClass()
        , REditorExplorerAbilityGroupView::StaticClass());

    Editor->RegisterMVVM(
        REditorDebugAndRunAbilityGroupModel::StaticClass()
        , REditorDebugAndRunAbilityGroupViewModel::StaticClass()
        , REditorDebugAndRunAbilityGroupView::StaticClass());

    Editor->RegisterMVVM(
        REditorBreakpointAbilityModel::StaticClass()
        , REditorBreakpointAbilityViewModel::StaticClass()
        , REditorBreakpointAbilityView::StaticClass());

    Editor->RegisterMVVM(
        REditorVariableAbilityModel::StaticClass()
        , REditorVariableAbilityViewModel::StaticClass()
        , REditorVariableAbilityView::StaticClass());
    
    Editor->RegisterMVVM(
        REditorCallStackAbilityModel::StaticClass()
        , REditorCallStackAbilityViewModel::StaticClass()
        , REditorCallStackAbilityView::StaticClass());

    Editor->RegisterMVVM(
        REditorOutputAbilityModel::StaticClass()
        , REditorOutputAbilityViewModel::StaticClass()
        , REditorOutputAbilityView::StaticClass());

    Editor->RegisterMVVM(
        REditorDebugConsoleModel::StaticClass()
        , REditorDebugConsoleViewModel::StaticClass()
        , REditorDebugConsoleView::StaticClass());

    Editor->RegisterMVVM(
        REditorFolderAbilityModel::StaticClass()
        , REditorFolderAbilityViewModel::StaticClass()
        , REditorFolderAbilityView::StaticClass());

    Editor->RegisterMVVM(
        REditorSceneOutlineAbilityModel::StaticClass()
        , REditorSceneOutlineAbilityViewModel::StaticClass()
        , REditorSceneOutlineAbilityView::StaticClass());

    Editor->RegisterMVVM(
        REditorMaterialPreviewAbilityModel::StaticClass()
        , REditorMaterialPreviewAbilityViewModel::StaticClass()
        , REditorMaterialPreviewAbilityView::StaticClass());

    Editor->RegisterMVVM(
        REditorEngineObjectAbilityGroupModel::StaticClass()
        , REditorEngineObjectAbilityGroupViewModel::StaticClass()
        , REditorEngineObjectAbilityGroupView::StaticClass());

    Editor->RegisterMVVM(
        REditorObjectPropertyAbilityModel::StaticClass()
        , REditorObjectPropertyAbilityViewModel::StaticClass()
        , REditorObjectPropertyAbilityView::StaticClass());

    //register the property
    Editor->RegisterMVVM(
        REditorNodePositionPropertyModel::StaticClass()
        , REditorNodePositionPropertyViewModel::StaticClass()
        , REditorNodePositionPropertyView::StaticClass());

    Editor->RegisterMVVM(
        REditorNodeRotationPropertyModel::StaticClass()
        , REditorNodeRotationPropertyViewModel::StaticClass()
        , REditorNodeRotationPropertyView::StaticClass());      

    Editor->RegisterMVVM(
        REditorNodeScalePropertyModel::StaticClass()
        , REditorNodeScalePropertyViewModel::StaticClass()
        , REditorNodeScalePropertyView::StaticClass());

    Editor->RegisterMVVM(
        REditorComponentPropertyModel::StaticClass()
        , REditorComponentPropertyViewModel::StaticClass()
        , REditorComponentPropertyView::StaticClass());

    Editor->RegisterMVVM(
        REditorAddComponentPropertyModel::StaticClass()
        , REditorAddComponentPropertyViewModel::StaticClass()
        , REditorAddComponentPropertyView::StaticClass());

    Editor->RegisterMVVM(
        REditorReflectedPropertyModel::StaticClass()
        , REditorReflectedPropertyViewModel::StaticClass()
        , REditorReflectedPropertyView::StaticClass());

    Editor->RegisterMVVM(
        REditorMeshMaterialPropertyModel::StaticClass()
        , REditorMeshMaterialPropertyViewModel::StaticClass()
        , REditorMeshMaterialPropertyView::StaticClass());

    RegisterMaterialGraphMVVM();
    RegisterStatusBarMVVM();
    RegisterNotificationMVVM();
    RegisterPageMVVM();
    RegisterEditorWindowMVVM();


    auto OpenResult=Editor->Open();

    if(OpenResult.bEmpty)
    {

        //create the main window
        REditorWindowGroupModel::Get()->CreateAndShowMainWindow(); 

        //打开欢迎页面
        OpenWelcomePage();

        //test script page
        //REditorWindowGroupModel::Get()->OpenPage(REditorTextFilePageModel::Create(SPath("D:/1.cs")));

        //test mesh page
        //auto Cube=REngineDefaultPackage::Get()->GetCubeMesh();
        //REditorWindowGroupModel::Get()->OpenPage(REditorMeshPageModel::Create(Cube));

        //test scene page
        // auto MeshScene = NewObject<RScene>();
        // {
        //     auto Light=NewObject<RSceneNode>();
        //     MeshScene->GetRootNode()->AddSubNode(Light);
        //     Light->SetNodeName(U"DirectionalLight");
        //     Light->SetWorldPosition(SVec3(0,0,0)); //any where is ok
        //     Light->SetWorldRotation(SQuat::FromEuler(SVec3(CMathBase::DegreeToRadian(-45.f),0,0)));
        //     {
        //         auto LightComponent=Light->CreateAndAddComponent<RDirectionalLightComponent>();
        //     }

        //     auto GreyFloor=NewObject<RSceneNode>();
        //     MeshScene->GetRootNode()->AddSubNode(GreyFloor);
        //     GreyFloor->SetNodeName(U"GreyFloor");
        //     GreyFloor->SetWorldPosition(SVec3(0,0,-1));
        //     GreyFloor->SetScale(SVec3(10,10,1));
        //     {
        //         auto MeshComponent=GreyFloor->CreateAndAddComponent<RStaticMeshComponent>();
        //         MeshComponent->SetStaticMesh(REngineDefaultPackage::Get()->GetCubeMesh());
        //         MeshComponent->SetMaterials({REngineDefaultPackage::Get()->GetDefaultMaterial()});

        //     }

        //     auto Camera=NewObject<RSceneNode>();
        //     MeshScene->GetRootNode()->AddSubNode(Camera);
        //     Camera->SetNodeName(U"Camera");
        //     auto CameraComponent=Camera->CreateAndAddComponent<RCameraComponent>();
        //     Camera->SetWorldPosition(SVec3(0,-3,2));
        //     Camera->SetWorldRotation(SQuat::FromEuler(SVec3(CMathBase::DegreeToRadian(-30.f),0,0))); 
        //     MeshScene->BeginPlay();    
        // }
        // REditorWindowGroupModel::Get()->OpenPage(REditorScenePageModel::Create(U"TestSceneFilePath" ,MeshScene));

        //test texture page
        //auto Texture=REngineDefaultPackage::Get()->GetEngineIcon();
        //REditorWindowGroupModel::Get()->OpenPage(REditorTexturePageModel::Create(Texture));
    
    
        //test material page
        // auto Material=NewObject<RMaterial>();
        // auto MaterialGraph=NewObject<RMaterialGraphModel>();
        // auto FloatNode=NewObject<RMaterialFloatNodeModel>(MaterialGraph);
        // FloatNode->Value=0.5f;
        // MaterialGraph->AddNode(FloatNode);

        // auto BRDFNode=NewObject<RMaterialBRDFNodeModel>(MaterialGraph);
        // MaterialGraph->AddNode(BRDFNode);

        // REditorWindowGroupModel::Get()->OpenPage(
        //     REditorMaterialPageModel::Create(
        //     U"TestMaterialFilePath"
        //     ,Material
        //     ,MaterialGraph
        //     )
        // );


    }

}
